import React, { useMemo, useState } from 'react'

export default function index() {

  let [a,setA] = useState(0)
  let [b,setB] = useState(0)

  const add = () => {
    setA(a + 1)
    setB(b + 1)
  }

  const sub = () => {
    setA(a - 1)
    setB(b - 1)
  }
  let c = useMemo(() => a + b, [])// 初始化执行一次

  let d = useMemo(() => a + b, [a, b])

  return (
    <>
      <div>C:{ c }</div>
      <div>D:{ d }</div>
      <button onClick={add}>a,b加一</button>
      <button onClick={sub}>a,b减一</button>
    </>
  )
}
